class Planet
	attr_reader( :x, :y, :government_number, :economy_type, :radius, :tech_level,
	  :productivity, :population, :name)
	
	  @@pairs = "..LEXEGEZACEBISO" + "USESARMAINDIREA." +  "ERATENBERALAVETI" + "EDORQUANTEISRION"
	  
	def initialize(x, y)
		@x = x
		@y = y
	end
	
	def initialize(seed)
		@x = seed.value2 >> 8
		@y = seed.value1 >> 8
		@government_number = (seed.value2 >> 3) & 7
		@economy_type = (seed.value1 >> 8) & 7
		if (@government_number <= 1)
			@economy_type = @economy_type | 2
		end
		
		# Tech level
		@tech_level = (seed.value2 >> 8) & 3
		@tech_level = @tech_level + (@economy_type ^ 7)
		@tech_level = @tech_level + (@government_number >> 1)
		if (@government_number & 1) == 1
		  @tech_level = @tech_level + 1
        end
		
		# Population
		@population = 4 * @tech_level
		@population = @population + @economy_type
		@population = @population + (@government_number + 1)
		
		# Productivity
		@productivity = ((@economy_type^7) + 3) * (@government_number + 4)
		@productivity = @productivity * (@population * 8)
		
		# Radius calculation
		@radius = @x
		@radius = @radius + (256 * (((seed.value3 >> 8) & 15) + 11))
		
		# Generate name
		@name = ""
		long_name_flag = seed.value1 & 64
		add_to_name(seed)
		RandomGenerator.tweak_seed(seed)
		add_to_name(seed)
		RandomGenerator.tweak_seed(seed)
		add_to_name(seed)
		RandomGenerator.tweak_seed(seed)
		add_to_name(seed)
		RandomGenerator.tweak_seed(seed)
		if (long_name_flag == 0)
		  @name = @name.slice(0, 6)
        end
		@name.delete!(".")
	end

	def add_to_name(seed)
	  	index = 2 * ((seed.value3>>8)&31)
		#puts "Pair index: " + index.to_s + "; Seed index: " + seed.value3.to_s
		@name.concat(@@pairs.slice(index, 2))
    end
end